var myScroll,
	pullDownEl, pullDownOffset,
	pullUpEl, pullUpOffset,
	generatedCount = 0;


function pullDownAction () {
	setTimeout(function () {
		window.location.reload();
		myScroll.refresh();
	}, 1000);
}
function pullUpAction () {
	setTimeout(function () {	
		console.log("上拉加载...");
		myScroll.refresh();		// 数据加载完成后，调用界面更新方法 Remember to refresh when contents are loaded (ie: on ajax completion)
	
		$(".pullUpLabel").html("没有更多数据了.");
	}, 1000);	
}


$(function(){
	$(".wuliu").show();
    console.log($("#emsCompany").val());
    console.log($("#emsId").val());
    $.ajax({
         type: "get",
         url: " /weishang/trade/logisticsInfo.do",
         dataType: "json",
  			 data: {
  			 	logisticsCompany:$("#emsCompany").val(),
  			 	logisticsId:$("#emsId").val(),
				id:"1",
				valicode:"",
				temp:""
  				},
    	success: function(date){
				var json=eval(date);
				if(json["data"].length==1){
					$(".emsListOne").show();
					$(".emsList").hide();
					$(".emsListTwo").hide();
					$(".emsInfoOneS").html(da);
					$(".emsTimeOneS").html(daTime);
				}else if(json["data"].length==2){
					$(".emsListTwo").show();
					$(".emsListOne").hide();
					$(".emsList").hide();
					for (var i=0;i<json["data"].length;i++){
						var daTime=json.data[i].time;
						var da=json.data[i].context;
						console.log(da);
						if(i==0){
							$(".emsInfoOne").html(da);
							$(".emsTimeOne").html(daTime);
							
						}else{
							$(".emsInfoTwo").html(da);
							$(".emsTimeTwo").html(daTime);
						}
					}
				}else{
					for (var i=0;i<json["data"].length;i++){
						var daTime=json.data[i].time;
						var da=json.data[i].context;
						console.log(da);
						$(".emsListOne").hide();
						$(".emsListTwo").hide();
						$(".emsList").show();
						if(i==0){
							$(".emsInfoOne").html(da);
							$(".emsTimeOne").html(daTime);
							
						}else if(i>0&&i<json["data"].length-1){
							$(".emsList").append("<div class='grayCircle'><div></div></div><div class='emsLiZ'><div class='emsInfo'>"+da+"</div><div class='emsTime'>"+daTime+"</div></div>");
//							$(".emsInfo").html(da);
//							$(".emsTime").html(daTime);
						}else{
							$(".emsList").append("<div class='firstEms'><div></div></div><div class='emsLiZ'><div class='emsInfoTwo'></div><div class='emsTimeTwo'></div></div>");
							
							$(".emsInfoTwo").html(da);
							$(".emsTimeTwo").html(daTime);
						}
						
					}
				}
				
				$(".qiye_sbt").hide();
				$(".qiye_sbt2").show();
         },
		 error:function(){
				$(".emsListOne").show();
		 }
     });	
    
    
	

	// 收藏的切换
	// $(".specialCol").on("click",function(){
	// 	$(".collectionSpecial").show();
	// 	$(".collectionShop").hide();
	// 	$(".collectionItem").hide();
	// 	$(".specialCol").addClass("collectionAction").siblings().removeClass("collectionAction");
	// })
	// $(".shopCol").on("click",function(){
	// 	$(".collectionSpecial").hide();
	// 	$(".collectionShop").show();
	// 	$(".collectionItem").hide();
	// 	$(".shopCol").addClass("collectionAction").siblings().removeClass("collectionAction");
	// })
	// $(".itemCol").on("click",function(){
	// 	$(".collectionSpecial").hide();
	// 	$(".collectionShop").hide();
	// 	$(".collectionItem").show();
	// 	$(".itemCol").addClass("collectionAction").siblings().removeClass("collectionAction");
	// })

});

window.onload=function(){
	
    
    pullDownEl = document.getElementById('pullDown');
	//pullDown
	pullUpEl = document.getElementById('pullUp');
	//pullUp
	pullDownOffset = pullDownEl.offsetHeight;
	pullUpOffset = pullUpEl.offsetHeight;
	
	var id='list';
	//list
	var yLen=40;
	
	var hei=document.getElementById(id).maxScrollY;
	
	myScroll = new iScroll(id, {
		useTransition: false,
		topOffset: pullDownOffset,
		onRefresh: function () {
			if (pullDownEl.className.match('loading')) {
				pullDownEl.className = '';
				pullDownEl.querySelector('.pullDownLabel').innerHTML = '下拉刷新...';
				//pullDownLabel
			} else if (pullUpEl.className.match('loading')) {
				pullUpEl.className = '';
				pullUpEl.querySelector('.pullUpLabel').innerHTML = '上拉加载更多...';
				//pullUpLabel
			}
		},
		onScrollMove: function () {
			if (this.y >= yLen && !pullDownEl.className.match('flip')) {
				pullDownEl.className = 'flip';
				pullDownEl.querySelector('.pullDownLabel').innerHTML = '松手开始更新...';
				//pullDownLabel
				this.minScrollY = 0;
			} else if (this.y < yLen && pullDownEl.className.match('flip')) {
				pullDownEl.className = '';
				pullDownEl.querySelector('.pullDownLabel').innerHTML = '下拉刷新...';
				//pullDownLabel
				this.minScrollY = -pullDownOffset;
			}
			else if (this.y < (this.maxScrollY - yLen) && !pullUpEl.className.match('flip')) {
				pullUpEl.className = 'flip';
				pullUpEl.querySelector('.pullUpLabel').innerHTML = '松手开始更新...';
				//pullUpLabel
				this.maxScrollY = this.maxScrollY;
			} else if (this.y > (this.maxScrollY + yLen) && pullUpEl.className.match('flip')) {
				pullUpEl.className = '';
				pullUpEl.querySelector('.pullUpLabel').innerHTML = '上拉加载更多...';
				//pullUpLabel
				this.maxScrollY = pullUpOffset;
			}
			//手指滑出屏幕 的时候
		      if(this.pointY < 5){
		    	  	//loading图
		    		 $(".loadingBg").show();
		    		 $(".loadingGif").show();

		    	  window.location.reload();
		    	  this.scrollTo(this.maxScrollY, this.maxScrollY, 200);
			    }
		},
		onScrollEnd: function () {
			if (pullDownEl.className.match('flip')) {
				pullDownEl.className = 'loading';
				pullDownEl.querySelector('.pullDownLabel').innerHTML = '加载中...';	
				//pullDownLabel
				pullDownAction();
			}
				else if (pullUpEl.className.match('flip')) {
				pullUpEl.className = 'loading';
				pullUpEl.querySelector('.pullUpLabel').innerHTML = '加载中...';
				//pullUpLabel
				pullUpAction();
			}
			
		}
	});
	
	setTimeout(function () { document.getElementById(id).style.left = '0'; }, 800);


}


